home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
sound
/
fixaiff_jf
/
fixaiff.jf
< prev
next >
Wrap
Text File
|
1999-05-17
|
6KB
|
224 lines
\ FixAIFF V1.1
\ Forth Program JForth Professional V3.1.
\ by Bob Dickow (dickow@uidaho.edu)
\
\ ...some AIFFs won't work in some programs
\ such as Petsoff's DelFX player/recorder
\ for the Delfina card. The problem is a
\ simple one: The variables in the SSND
\ chunk header (before the sample data) is
\ sometimes set, but DelFX (up to v 1.02 so
\ far to date) needs them to be zeros.
\ To use this program, simply call it from
\ the shell, with the first parameter as
\ the source sample file (AIFF) and the
\ second parameter as the target file. The
\ target is a new file with the modifications
\ needed. The source file is untouched.
\ includes:
\ include? DEBUG{ jdev:debugger
include? clone cl:topfile
include? iff.check jiff:IFF_Support
\ you will need to declare 'AIFF' 'COMM' and 'SSND'
\ in jiff:iff.j
\ the following is available from the JForth web
\ site's user contributed code page. I wrote it!
\ It parses command line arguments, like C, sort of.
\ the site is at http:home.tampabay.rr.com/jforth/
include? carg ju:parsecli
ANEW Task-FixAIFF
256 constant buffsize
: NameFromFH() ( fh buffer -- err ) \ specific to this prg.
1+ >abs buffsize
CALL dos_lib NameFromFH
;
VARIABLE IFFSourceHandle
VARIABLE IFFTargetHandle
IFFSourceHandle off \ for safety
IFFTargetHandle off \ for safety
40960 constant SSNDbuffsize
create SourcePathName buffsize 2+ allot align
create TargetPathName buffsize 2+ allot align
create SourceNamebuff buffsize 2+ allot align
create TargetNamebuff buffsize 2+ allot align
DEFER SAVED-Iff.Process.chunk
DEFER SAVED-Iff.process.Form
\ general exit routine, normal or when in error:
: FixEXIT ( $EXITMSG -- )
count type cr
What's SAVED-IFF.Process.Chunk is IFF.Process.Chunk
What's SAVED-Iff.process.Form is IFF.process.form
IFF.Close
IFFTargetHandle @ ?dup if dup FCLOSE off then
IFFSourceHandle @ ?dup if dup FCLOSE off then
Abort
;
\ strips quotes, if needed, from command line arguments:
: stripquotes ( addr count buffer -- )
dup dup off >r
$append
r@ 1+ c@ ascii " = if \ it's a quoted string, so strip
r@ 2+ r@ 1+ r@ c@ 1- cmove r@ dup c@ 2- swap c!
then
rdrop
;
VARIABLE DATASIZE
\ writes out string or numeric data to the target.
: write.target ( addr count -- )
IFFTargetHandle @ -rot
dup
>r FWRITE r> - if
" Error Writing Target AIFF" FixEXIT
then
;
: $>target ( stringaddr -- )
count write.target
;
VARIABLE BUFF
: n>target ( n -- )
BUFF ! BUFF CELL write.target
;
\ iff handling routines:
: iff.handle.AIFF ( size -- )
" FORM" $>target n>target " AIFF" $>target
;
: iff.handle.COMM { size | data -- }
size iff.read.data ?dup if
-> data
\ do stuff...
" COMM" $>target size n>target
data size write.target
\
data freeblock
else
drop
then
;
: iff.handle.SSND { size | data total -- }
size 8 - -> total
" SSND" $>target size n>target \ write out chunk id
0 n>target 0 n>target \ write out eight zeros.
iff.where 8 + iff.seek
Begin
total SSNDBuffsize < if total else SSNDBuffsize then dup >r \ size set for allocation
iff.read.data ?dup if
-> data
data r@ write.target
data freeblock
else
rdrop " File Read Error" FixEXIT
then
total r> - -> total
total 0= until
;
: My.IFF.HANDLE.FORM ( size -- , scan chunks in FORM )
1 iff-nested +!
iff.read.type 'AIFF' = if-not " Not an AIFF FORM!" FixEXIT else
dup Iff.Handle.AIFF
then \ drop \ .chkid cr
4 - ( subtract 4 for type )
BEGIN
dup 0>
iff-stop @ 0= AND \ check for stop 00002
WHILE iff.scan 8 + ( account for header) -
REPEAT drop
-1 iff-nested +!
;
: My.Iff.Process.Chunk ( size chkid -- )
dup 'FORM' = if
drop
iff.process.FORM
else
dup 'COMM' = if
drop
iff.handle.COMM
else
'SSND' = if
iff.handle.SSND
else
drop
then
then
then
;
\ called routine. Call from CLI.
: Run ( -- )
IFFSourceHandle off
IFFTargetHandle off
0" $VER: fixaiff V1.1 (5.1.99)" drop \ store version info for AmigaDOS
NCARG 2 = not if ." USAGE: fixaiff <sourceaiff> <targetaiff>"
cr ." <sourceaiff> = aiff file to process." cr
." <targetaiff> = file name for fixed aiff file." cr
" WARNING: <targetaiff> will be overwritten if it already exists."
FixEXIT
then
\ these two lines parse the file names from the cli arguments:
1 CARG SourcePathName stripquotes
2 CARG TargetPathName stripquotes
\ check for same filename in same directory:
OLD
TargetPathName $FOPEN ?dup if
dup IFFTargetHandle !
TargetNamebuff NameFromFH() if-not " Error: Target pathname too long?" FixEXIT then
else
TargetNamebuff off
then
OLD
SourcePathName $FOPEN ?dup if IFFSourceHandle ! else " Error opening source aiff." FixEXIT then
IFFSourceHandle @ SourceNamebuff NameFromFH() if-not " Error: Source pathname too long?" FixEXIT then
SourceNameBuff 0count TargetNameBuff 0count -rot -rot max
COMPARE if-not " ERROR: Sourceaiff = Targetaiff" FixEXIT then
\ All is ok, so proceed...
\ close the tested files first, if they're open:
IFFSourceHandle @ ?dup if FCLOSE IFFSourceHandle off then
IFFTargetHandle @ ?dup if FCLOSE IFFTargetHandle off then
\ check to see if the sourceaiff is a real iff file:
What's Iff.Process.Chunk is SAVED-Iff.Process.chunk
What's Iff.Process.Form is SAVED-Iff.Process.Form
'C My.Iff.Process.Chunk is IFF.Process.Chunk
'C My.Iff.Handle.Form is IFF.Process.FORM
NEW
TargetPathName $FOPEN ?dup if IFFTargetHandle ! else " Error opening target " FixEXIT then
OLD
SourcePathName $Iff.DoFile? if " Error opening source aiff." FixEXIT then
" OK" FixEXIT
;
\ END FixAIFF file